package com.tomshidi.security.distributed.order.controller;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author TomShiDi
 * @description
 * @date 2020/12/5 15:18
 **/
@RestController
public class OrderController {

    @GetMapping("/r1")
    @PreAuthorize("hasAnyAuthority('p1')")
    public String r1() {
        String principal = (String) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
        return principal + " 访问资源1";
    }

    @GetMapping("/r2")
    @PreAuthorize("hasAnyAuthority('p2')")
    public String r2() {
        return "访问资源2";
    }

    @GetMapping("/r3")
    public String r3() {
        return "访问资源3";
    }
}
